package com.example.myshop.service;

import com.example.myshop.entity.User;
import com.example.myshop.service.ex.ServiceException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Service;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@SpringBootTest
@RunWith(SpringRunner.class)
@Service
public class userservicetest {
    @Autowired UserService userService;

    @Test
    public void reg(){
        User user=new User();
        user.setUsername("zq");
        user.setPassword("123");
        user.setBankAccount("1234567891234567");
        user.setUserType("123123");
        user.setGender(0);
        userService.save(user);
        try {
            System.out.println("注册成功");
        } catch (ServiceException e) {
            //获取类的对象，再获取类的名称
            System.out.println(e.getClass().getSimpleName());
            //获取异常具体描述信息
            System.out.println(e.getMessage());
        }
    }

    @Test
    public void login(){
        User user=userService.login("zq123","123456789");
        System.out.println(user.toString());
    }

    @Test
    public void changepassword(){
        userService.changePassword(1642459928473444354L,"zq123","987654321","123456789");

    }
    @Test
    public void checkall(){
        List<User>users= userService.checkAllUsers();
        System.out.println(users.toString());
    }
    @Test
    public void getmoney(){
        User user= userService.getMoney(1642459928473444354L);
        System.out.println(user.toString());
    }
}
